<template>
  <div class="common">

    <div class="form-box">
      <el-form ref="form" :model="pageParams" label-width="90px">
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item prop="personName" label="快递员账号:">
              <el-input v-model="pageParams.account" placeholder="请输入快递员账号" size="small" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="personName" label="快递员姓名:">
              <el-input v-model="pageParams.name" placeholder="请输入快递员姓名" size="small" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="personName" label="快递手机号:">
              <el-input v-model="pageParams.mobile" placeholder="请输入快递手机号" size="small" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="personName" label="所属机构:">
              <el-select
                v-model="pageParams.agentId"
                placeholder="请选择所属机构"
                style="width:100%"
                clearable
              >
                <el-tree
                  node-key="id"
                  :data="treeData"
                  class="add_tree"
                  :props="defaultProps"
                  :expand-on-click-node="false"
                  :check-on-click-node="true"
                >
                  <span slot-scope="{data}" class="custom-tree-node">
                    <el-option
                      style="padding: 0"
                      :label="data.name"
                      :value="data.id"
                    /></span></el-tree>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-button type="primary" @click="searchCourier">搜索</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-col>

        </el-row>
      </el-form>
    </div>

    <!-- Table 表格 -->
    <div class="table">
      <!-- 放置table组件 -->
      <el-table :data="list">
        <!-- 放置列 -->
        <el-table-column
          prop=""
          align="center"
          label="序号"
          type="index"
        />
        <el-table-column prop="account" align="center" label="快递员账号" />
        <el-table-column prop="name" align="center" label="快递员账号" />
        <el-table-column prop="mobile" align="center" label="快递员手机" />
        <el-table-column prop="agency.name" align="center" label="所属机构" />
        <el-table-column prop="workStatus" align="center" label="工作状态">
          <template v-slot="{row}">
            <span>{{ row.status===1?'上班':row.status===0 ? '休息':'无' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="" align="center" label="操作">

          <template v-slot="{row}">

            <el-button size="mini" type="text" @click="$router.push(`/worManagement/workAllot/${row.userId}`)">作业范围分配</el-button>

          </template>

        </el-table-column>

      </el-table>
    </div>

    <!-- 分页 -->
    <!-- 放置分页组件 -->
    <el-row type="flex" style="height:60px" align="middle" justify="center">
      <!-- 放置分页组件 -->
      <el-pagination
        :current-page="pageParams.page"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="parseInt(total)"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>

  </div>
</template>
<script>
import { getCourierAPI, getOrganizationAPI } from '@/api/staffManagement'
export default {
  data() {
    return {
      total: 0,
      list: [],
      // 获取列表   模糊搜索
      pageParams: {
        account: '', // 司机编号 账号
        name: '', // 名字
        mobile: '', // 电话
        agentId: '', // 机构ID
        page: 1, // 页码
        pageSize: 10 // 每页条数
      },
      // 树形控件数据
      defaultProps: {
        label: 'name',
        children: 'children',
        value: '',
        emitPath: false
      },
      treeData: [],
      label: '',
      selectOption: '',
      form: {
        account: '',
        agentId: -1 && '',
        name: '',
        phone: ''
      }

    }
  },
  created() {
    this.getCourier()
    this.organizationChange()
  },
  methods: {
    // 获取快递员管理列表
    async getCourier() {
      const res = await getCourierAPI(this.pageParams)
      console.log('res  ----->  ', res)
      this.list = res.items
      this.total = res.counts
    },

    // 搜索
    searchCourier() {
      this.pageParams.page = 1
      this.pageParams.pageSize = 10

      this.getCourier(this.pageParams)
    },
    // 重置
    resetForm() {
      this.pageParams = {
        account: '', // 司机编号 账号
        name: '', // 名字
        mobile: '', // 电话
        agentId: '', // 机构ID
        page: 1, // 页码
        pageSize: 10 // 每页条数
      }
      this.getCourier(this.pageParams)
    },
    // 分页函数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageParams.pageSize = val
      this.getCourier()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageParams.page = val
      this.getCourier(this.pageParams)
    },
    // 获取树状机构信息
    async organizationChange() {
      const res = await getOrganizationAPI()
      this.treeData = JSON.parse(res)
    }
  }

}
</script>
<style scoped lang="scss">

.common{
  background-color: #f4f6f8;
  padding:20px ;
}
.form-box{
  background-color: #ffffff;

  padding:20px 30px;

}
.table{
  margin-top: 20px;

}

</style>
